package com.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 描述：Cart 类的用途 整个购物车
 * 日期：2025/1/18
 */
public class Cart {
    List<CartItem> items;
    public Integer countNum;//商品数量
    public Integer countType;//商品种类
    public BigDecimal totalAmount;
    public BigDecimal reduce;//减免价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if (items != null && items.size()>0)
        {
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }


    public Integer getCountType() {
        int count = 0;
        if (items != null && items.size()>0)
        {
            count = items.size();
        }
        return count;
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        for (CartItem item : items) {
            BigDecimal totalPrice = item.getTotalPrice();
            amount = amount.add(totalPrice);
        }

        amount.subtract(this.getReduce());
        return amount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
